Reactivate use of 'va_copy'.
authoroliskoli <oliskoli>
Fri, 7 Mar 2008 23:14:41 +0000 (23:14 +0000)
committeroliskoli <oliskoli>
Fri, 7 Mar 2008 23:14:41 +0000 (23:14 +0000)
cet_util.c
config.h.in
configure
configure.in
defs.h
gbfile.c
gbfile.h
util.c

index 19e76f24d6e4a2a8ce942d8e413136531736e685..d8fd3930ff9ae183c5e67a8bd4a6ad8b5ca7f462 100644 (file)
@@ -1154,38 +1154,30 @@ cet_disp_character_set_names(FILE *fout)
 
 int cet_gbfprintf(gbfile *stream, const cet_cs_vec_t *src_vec, const char *fmt, ...)
 {
-       char buff[128];
-       int res, ct;
+       int res;
+       char *cout;
        va_list args;
-       char *cout = buff;
 
        va_start(args, fmt);
-       ct = vsnprintf(buff, sizeof(buff), fmt, args);
+       xvasprintf(&cout, fmt, args);
        va_end(args);
 
-       if (ct >= (int)sizeof(buff)) {
-               cout = xmalloc(ct + 1);
-               va_start(args, fmt);
-               vsnprintf(cout, ct + 1, fmt, args);
-               va_end(args);
-       }
-
        if (global_opts.charset != src_vec)
        {
                if (src_vec != &cet_cs_vec_utf8) {
                        char *ctemp = cet_str_any_to_utf8(cout, src_vec);
-                       if (cout != buff) xfree(cout);
+                       xfree(cout);
                        cout = ctemp;
                }
                if (global_opts.charset != &cet_cs_vec_utf8) {
                        char *ctemp = cet_str_utf8_to_any(cout, global_opts.charset);
-                       if (cout != buff) xfree(cout);
+                       xfree(cout);
                        cout = ctemp;
                }
        }
 
        res = gbfprintf(stream, "%s", cout);
-       if (cout != buff) xfree(cout);
+       xfree(cout);
        
        return res;
 }
index 37c53f2bc864877fca15475c8f335969020ccc05..ce0fe28b27176a64c38cdb9af325632390ee5b66 100644 (file)
@@ -9,6 +9,9 @@
 /* 1 to enable all the filters. */
 #undef FILTERS_ENABLED
 
+/* Define to 1 if you have the <inttypes.h> header file. */
+#undef HAVE_INTTYPES_H
+
 /* Defined if you have libexpat */
 #undef HAVE_LIBEXPAT
 
 /* Define to 1 if you have the `z' library (-lz). */
 #undef HAVE_LIBZ
 
+/* Define to 1 if you have the <memory.h> header file. */
+#undef HAVE_MEMORY_H
+
 /* Define to 1 if you have the `nanosleep' function. */
 #undef HAVE_NANOSLEEP
 
 /* Define to 1 if you have the `sleep' function. */
 #undef HAVE_SLEEP
 
+/* Define to 1 if you have the <stdint.h> header file. */
+#undef HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#undef HAVE_STDLIB_H
+
+/* Define to 1 if you have the <strings.h> header file. */
+#undef HAVE_STRINGS_H
+
+/* Define to 1 if you have the <string.h> header file. */
+#undef HAVE_STRING_H
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#undef HAVE_SYS_STAT_H
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#undef HAVE_SYS_TYPES_H
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#undef HAVE_UNISTD_H
+
+/* Define if we have va_copy */
+#undef HAVE_VA_COPY
+
+/* Define as 1 if your va_list type is an array */
+#undef HAVE_VA_LIST_AS_ARRAY
+
+/* Define if we have __va_copy */
+#undef HAVE___VA_COPY
+
 /* 1 to enable as many formats as possible */
 #undef MAXIMAL_ENABLED
 
@@ -54,6 +90,9 @@
 /* 1 to enable shapefile support */
 #undef SHAPELIB_ENABLED
 
+/* Define to 1 if you have the ANSI C header files. */
+#undef STDC_HEADERS
+
 /* Define to 1 if your processor stores words with the most significant byte
    first (like Motorola and SPARC, unlike Intel and VAX). */
 #undef WORDS_BIGENDIAN
index a7bb3a6e772614ed1f1ce6f2514af8d25bfc6ca9..3414cf45de529d8b3d0bb3790aaaf890ecdeb545 100755 (executable)
--- a/configure
+++ b/configure
@@ -4666,6 +4666,212 @@ fi
 done
 
 
+#
+# Checks for how the system handles va_list
+# paul.bromiley@man.ac.uk
+#
+{ echo "$as_me:$LINENO: checking for va_copy" >&5
+echo $ECHO_N "checking for va_copy... $ECHO_C" >&6; }
+if test "${ac_cv_c_va_copy+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdarg.h>
+int
+main ()
+{
+va_list ap1, ap2;
+    va_copy(ap1,ap2);
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+        test -z "$ac_c_werror_flag" ||
+        test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  ac_cv_c_va_copy="yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+       ac_cv_c_va_copy="no"
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_c_va_copy" >&5
+echo "${ECHO_T}$ac_cv_c_va_copy" >&6; }
+if test "$ac_cv_c_va_copy" = "yes"
+then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_VA_COPY 1
+_ACEOF
+
+fi
+{ echo "$as_me:$LINENO: checking for __va_copy" >&5
+echo $ECHO_N "checking for __va_copy... $ECHO_C" >&6; }
+if test "${ac_cv_c___va_copy+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdarg.h>
+int
+main ()
+{
+va_list ap1, ap2;
+    __va_copy(ap1,ap2);
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+        test -z "$ac_c_werror_flag" ||
+        test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  ac_cv_c___va_copy="yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+       ac_cv_c___va_copy="no"
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_c___va_copy" >&5
+echo "${ECHO_T}$ac_cv_c___va_copy" >&6; }
+if test "$ac_cv_c___va_copy" = "yes"
+then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE___VA_COPY 1
+_ACEOF
+
+fi
+
+#
+# Does this platform require array notation to assign to a va_list?
+#
+{ echo "$as_me:$LINENO: checking va_list assignments need array notation" >&5
+echo $ECHO_N "checking va_list assignments need array notation... $ECHO_C" >&6; }
+if test "${ac_cv_valistisarray+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test "$cross_compiling" = yes; then
+  ac_cv_valistisarray=false
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdlib.h>
+                    #include <stdarg.h>
+                    void foo(int i, ...) {
+                       va_list ap1, ap2;
+                       va_start(ap1, i);
+                       ap2 = ap1;
+                       if (va_arg(ap2, int) != 123 || va_arg(ap1, int) != 123) { exit(1); }
+                       va_end(ap1); va_end(ap2);
+                    }
+                    int main()
+                    { foo(0, 123); return(0); }
+_ACEOF
+rm -f conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_valistisarray=false
+else
+  echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+ac_cv_valistisarray=true
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+
+
+fi
+
+
+if test "$ac_cv_valistisarray" = true ; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_VA_LIST_AS_ARRAY 1
+_ACEOF
+
+       { echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
+else
+       { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
 ac_config_files="$ac_config_files Makefile gbversion.h xmldoc/makedoc tools/mkcapabilities win32/gpsbabel.rc jeeps/Makefile shapelib/Makefile zlib/empty"
 
 cat >confcache <<\_ACEOF
@@ -5807,3 +6013,4 @@ if test "$no_create" != yes; then
   $ac_cs_success || { (exit 1); exit 1; }
 fi
 
+
index c2556113dcf6f9b271e53131a5f62c6dfcb25395..8ca40421745208293a32a24047d652b750da4951 100644 (file)
@@ -341,5 +341,53 @@ AC_SUBST(DOCDIR)
 # AC_CHECK_FUNCS([atexit floor localtime_r memmove memset pow select sqrt strchr strcspn strdup strerror strncasecmp strrchr strspn strstr strtol strtoul])
 AC_CHECK_FUNCS([nanosleep sleep])
 
+#
+# Checks for how the system handles va_list
+# paul.bromiley@man.ac.uk
+#
+dnl **** Check for va_copy ****
+AC_CACHE_CHECK([for va_copy], ac_cv_c_va_copy,
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>]], [[va_list ap1, ap2;
+    va_copy(ap1,ap2);
+   ]])],[ac_cv_c_va_copy="yes"],[ac_cv_c_va_copy="no"])
+ )
+if test "$ac_cv_c_va_copy" = "yes"
+then
+    AC_DEFINE(HAVE_VA_COPY, 1, [Define if we have va_copy])
+fi
+AC_CACHE_CHECK([for __va_copy], ac_cv_c___va_copy,
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>]], [[va_list ap1, ap2;
+    __va_copy(ap1,ap2);
+   ]])],[ac_cv_c___va_copy="yes"],[ac_cv_c___va_copy="no"])
+ )
+if test "$ac_cv_c___va_copy" = "yes"
+then
+    AC_DEFINE(HAVE___VA_COPY, 1, [Define if we have __va_copy])
+fi
+
+#
+# Does this platform require array notation to assign to a va_list?
+#
+AC_MSG_CHECKING(va_list assignments need array notation)
+AC_CACHE_VAL(ac_cv_valistisarray,
+        [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdlib.h>
+                    #include <stdarg.h>
+                    void foo(int i, ...) {
+                       va_list ap1, ap2;
+                       va_start(ap1, i);
+                       ap2 = ap1;
+                       if (va_arg(ap2, int) != 123 || va_arg(ap1, int) != 123) { exit(1); }
+                       va_end(ap1); va_end(ap2);
+                    }
+                    int main()
+                    { foo(0, 123); return(0); }]])],[ac_cv_valistisarray=false],[ac_cv_valistisarray=true],[ac_cv_valistisarray=false])])
+                                            
+if test "$ac_cv_valistisarray" = true ; then
+       AC_DEFINE(HAVE_VA_LIST_AS_ARRAY, 1, [Define as 1 if your va_list type is an array])
+       AC_MSG_RESULT(yes)
+else
+       AC_MSG_RESULT(no)
+fi
 AC_CONFIG_FILES([Makefile gbversion.h xmldoc/makedoc tools/mkcapabilities win32/gpsbabel.rc jeeps/Makefile shapelib/Makefile zlib/empty])
 AC_OUTPUT
+
diff --git a/defs.h b/defs.h
index d4be221f5806d16b403ac9002a1be29c0f576f4f..40b487eefbf0c5ad81fbafc14ccb4bf41becf941 100644 (file)
--- a/defs.h
+++ b/defs.h
 #  define NORETURN void
 #endif
 
+#ifndef HAVE_VA_COPY
+#  ifdef __va_copy
+#    define va_copy(DEST,SRC) __va_copy((DEST),(SRC))
+#  else
+#    ifdef HAVE_VA_LIST_AS_ARRAY
+#      define va_copy(DEST,SRC) (*(DEST) = *(SRC))
+#    else
+#      define va_copy(DEST,SRC) ((DEST) = (SRC))
+#    endif
+#  endif
+#endif
+
 /*
  * Common definitions.   There should be no protocol or file-specific
  * data in this file.
@@ -787,6 +799,7 @@ char *xstrrstr(const char *s1, const char *s2);
 void rtrim(char *s);
 char * lrtrim(char *s);
 int xasprintf(char **strp, const char *fmt, ...);
+int xvasprintf(char **strp, const char *fmt, va_list ap);
 char *strupper(char *src);
 char *strlower(char *src);
 signed int get_tz_offset(void);
index 109845cf6bb3dceea390396c0851c95b3fcbc6a7..a9e9c499e64acf83d369b6fc541c6ec34a8b7fec 100644 (file)
--- a/gbfile.c
+++ b/gbfile.c
@@ -289,18 +289,17 @@ gbfread(void *buf, const gbsize_t size, const gbsize_t members, gbfile *file)
 }
 
 /*
- * gbfprintf: (as fprintf)
+ * gbvfprintf: (as vfprintf)
  */
  
-int 
-gbfprintf(gbfile *file, const char *format, ...)
+int gbvfprintf(gbfile *file, const char *format, va_list ap)
 {
        int len;
        
        for (;;) {
                va_list args;
                
-               va_start(args, format);
+               va_copy(args, ap);
                len = vsnprintf(file->buff, file->buffsz, format, args);
                va_end(args);
 
@@ -329,6 +328,23 @@ gbfprintf(gbfile *file, const char *format, ...)
        return gbfwrite(file->buff, 1, len, file);
 }
 
+/*
+ * gbfprintf: (as fprintf)
+ */
+int 
+gbfprintf(gbfile *file, const char *format, ...)
+{
+       va_list args;
+       int result;
+       
+       va_start(args, format);
+       result = gbvfprintf(file, format, args);
+       va_end(args);
+       
+       return result;
+}
+
 /*
  * gbfputc: (as fputc)
  */
index 7b1d28a7b68afac6ab57899cc3bb4c97ceec9f60..545ebfc687b27c89127bc13a8efcce1e71411e5d 100644 (file)
--- a/gbfile.h
+++ b/gbfile.h
@@ -60,6 +60,7 @@ gbsize_t gbfread(void *buf, const gbsize_t size, const gbsize_t members, gbfile
 int gbfgetc(gbfile *file);
 char *gbfgets(char *buf, int len, gbfile *file);
 
+int gbvfprintf(gbfile *file, const char *format, va_list ap);
 int gbfprintf(gbfile *file, const char *format, ...);
 int gbfputc(int c, gbfile *file);
 int gbfputs(const char *s, gbfile *file);
diff --git a/util.c b/util.c
index 51a7e327124ffd8e5a7bc45ecdbe72d5007aeefd..d76b7ea3b823d62f1b051fa7df00e9124d4af9b3 100644 (file)
--- a/util.c
+++ b/util.c
@@ -299,6 +299,19 @@ xfputs(const char *errtxt, const char *s, FILE *stream)
 
 int
 xasprintf(char **strp, const char *fmt, ...)
+{
+       va_list args;
+       int res;
+       
+       va_start(args, fmt);
+       res = xvasprintf(strp, fmt, args);
+       va_end(args);
+       
+       return res;
+}
+
+int
+xvasprintf(char **strp, const char *fmt, va_list ap)
 {
 /* From http://perfec.to/vsnprintf/pasprintf.c */
 /* size of first buffer malloc; start small to exercise grow routines */
@@ -331,7 +344,7 @@ xasprintf(char **strp, const char *fmt, ...)
                        return -1;
                }
 
-               va_start(args, fmt);
+               va_copy(args, ap);
                outsize = vsnprintf(buf, bufsize, fmt, args);
                va_end(args);
                
@@ -383,6 +396,7 @@ xasprintf(char **strp, const char *fmt, ...)
        return outsize;
 }
 
+
 /* 
  * Duplicate a pascal string into a normal C string.
  */